package com.ilikesoup.instant.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

public class LogInterceptor implements MethodInterceptor, Observer {

    @Override
    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        if("toString".equals(method.getName())) {
            return methodProxy.invokeSuper(o, args);
        }
        System.out.println("------------------------------");
        System.out.println("before:"+ o);
        System.out.println(Thread.currentThread().getStackTrace()[2]);
        System.out.println("args:"+ Arrays.toString(args));
        Object invoke = methodProxy.invokeSuper(o, args);
        System.out.println("after:"+ o);
        System.out.println("------------------------------");
        return invoke;
    }

    @Override
    public void update(Observable o, Object arg) {
    }
}
